package com.tianji.remark.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tianji.api.dto.remark.LikedTimesDTO;
import com.tianji.common.utils.BeanUtils;
import com.tianji.common.utils.ObjectUtils;
import com.tianji.common.utils.UserContext;
import com.tianji.remark.domain.dto.LikeRecordFormDTO;
import com.tianji.remark.domain.po.LikedRecord;
import com.tianji.remark.mapper.LikedRecordMapper;
import com.tianji.remark.service.ILikedRecordService;
import com.tianji.remark.service.impl.LikedRecordServiceImpl;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 点赞记录表 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-03-26
 */
@RestController
@RequiredArgsConstructor
@Slf4j
public class LikedRecordController {

    private final ILikedRecordService likedRecordService;

    private final StringRedisTemplate redisTemplate;

    /**
     * 点赞业务
     * @param likeRecordFormDTO
     */
    @PostMapping("/likes")
    public void addLike(@RequestBody LikeRecordFormDTO likeRecordFormDTO) {
        likedRecordService.addLike(likeRecordFormDTO);
    }

    /**
     * 返回总的点赞数量
     */
    @GetMapping("/combine")
    public List<LikedTimesDTO> combineRecord(@RequestParam("ids") List<Long> ids) {
        return likedRecordService.getByIds(ids);
    }

    /**
     * 返回当前用户对所有业务的点赞情况
     */
    @GetMapping("/liked")
    public Map<Long, Boolean> isLiked(@RequestParam("ids") List<Long> ids) {
        return likedRecordService.isLiked(ids);
    }
}
